﻿using AutoMapper;
using D.Medicalcare.Domain.Entities;
using D.Medicalcare.ErrorCode;
using D.Medicalcare.Infrastructure.Interfaces;
using D.Medicalcare.Write.API.Application.Commands.PhysicalexaminationCommand;
using MediatR;

namespace D.Medicalcare.Write.API.Application.Handlers.PhysicalexaminationHarder
{
    public class UpdatePhysicalexaminationHarder : IRequestHandler<UpdatePhysicalexaminationCommand, APIResult<int>>
    {

        private readonly IBaseRepository<Physicalexamination> repository;

        public UpdatePhysicalexaminationHarder(IBaseRepository<Physicalexamination> repository)
        {
            this.repository = repository;
        }

        public async Task<APIResult<int>> Handle(UpdatePhysicalexaminationCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            var xi = repository.GetAll().Where(x=>x.physicalId== request.physicalId).First();
            xi.Remark = request.Remark;
          var a=  repository.Update(xi).Result;
            if (a > 0)
            {

                result.Code = APIEnum.Success;
                result.Msg = "修改成功";
                result.Data = a;


            }
            else
            {
                result.Code = APIEnum.Failed;
                result.Msg = "修改成功";
                result.Data = a;


            }
            return await Task.FromResult(result);

        }
    }
}
